package com.frinder.task.strategy.in;

import com.frinder.base.strategy.Strategy;
import com.frinder.task.strategy.in.biz.DbReceiveTaskStrategy;
import com.frinder.task.strategy.in.biz.SfReceiveTaskStrategy;
import com.frinder.task.strategy.in.biz.SkyEyeReceiveTaskStrategy;
import com.frinder.task.strategy.in.biz.WmsReceiveTaskStrategy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @ClassName ReceiveTaskHandler
 * @Description 接收任务处理器
 * @Author frinder
 * @Date 2019/10/17 14:55
 * @Verion 1.0
 */
@Component
public class ReceiveTaskHandler {

    @Autowired
    private WmsReceiveTaskStrategy wmsReceiveTaskStrategy;

    @Autowired
    private SkyEyeReceiveTaskStrategy skyEyeReceiveTaskStrategy;

    @Autowired
    private DbReceiveTaskStrategy dbReceiveTaskStrategy;

    @Autowired
    private SfReceiveTaskStrategy sfReceiveTaskStrategy;

    private ReceiveTaskBaseStrategy receiveTaskBaseStrategy;

    @PostConstruct
    public void post() {
        receiveTaskBaseStrategy = new ReceiveTaskBaseStrategy();
        // 注册责任链
        receiveTaskBaseStrategy
                .register(wmsReceiveTaskStrategy)
                .register(skyEyeReceiveTaskStrategy)
                .register(sfReceiveTaskStrategy)
                .register(dbReceiveTaskStrategy);
    }

    /**
     * 接收任务处理方法
     *
     * @param payload
     */
    @Strategy
    public void handle(ReceiveTaskPayload payload) {
        receiveTaskBaseStrategy.handle(payload);
    }

}
